package config

/**
 * @title 控制文件
 *
 * @author wz
 *
 * @date 2025/10/23 14:13
 *
 * @version 1.0
 */
import (
	"github.com/goccy/go-yaml"
	"log"
	"os"
)

type Config struct {
	App struct {
		Port string `yaml:"port"`
		Env  string `yaml:"env"`
	} `yaml:"app"`
	Database struct {
		Host           string `yaml:"host"`
		Port           int    `yaml:"port"`
		User           string `yaml:"user"`
		Password       string `yaml:"password"`
		DBName         string `yaml:"dbname"`
		MaxConnections int    `yaml:"max_connections"`
	} `yaml:"database"`
}

func LoadConfig() *Config {
	file, err := os.ReadFile("./config/config.yaml")
	if err != nil {
		log.Fatalf("配置文件读取失败: %v", err)
	}

	var cfg Config
	if err := yaml.Unmarshal(file, &cfg); err != nil {
		log.Fatalf("配置解析失败: %v", err)
	}
	return &cfg
}
